/*************************************************************************
	> File Name: EP37.cpp
	> Author: 
	> Mail: 
	> Created Time: 五  8/ 9 18:55:31 2019
 ************************************************************************/
#include <stdio.h>
#include <math.h>
#include <string.h>
#define max_n 1000000

int prime[max_n + 5] = {0};
int is_Prime[max_n + 5] = {1, 1};

void init() {
    for (int i = 2; i <= max_n; i++) {
        if (!is_Prime[i]) prime[++prime[0]] = i;
        for (int j = 1; j <= prime[0]; j++) {
            if (prime[j] * i > max_n) break;
            is_Prime[prime[j] * i] = 1;
            if (i % prime[j] == 0) break;
        }
    }
    return ;
}


int is_val(int n) {
	int x = n, h;
    while (x) {
        if (is_Prime[x] != 0) return 0;
        x /= 10;
    }
    h = (int)pow(10, floor(log10(n)));
    x = n;
    while (x) {
        if (is_Prime[x] != 0) return 0;
        x %= h;
        h /= 10;
    }
    return 1;
}

int main() {
    init();
    int sum = 0, flag = 11;
    for (int i = 1; i <= prime[0]; i++) {
        if (prime[i] < 10) continue;
        if (!is_val(prime[i])) continue;
        sum += prime[i];
        printf("%d\n", prime[i]);
        flag -= 1;
        if (!flag) break;
    }
    printf("%d\n", sum);
    return 0;
}
